
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>供应链查询</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input v-model="formInline.ename" placeholder="客户名称"></el-input>
      </el-form-item>
      <el-form-item label="搜索：">
        <el-input
          v-model="formInline.phonenum"
          placeholder="管理员手机号"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!--列表-->
    <div style="border: 1px solid lightgray">
      <div
        style="width: 100%; height: 50px; background-color: rgb(243, 243, 243)"
      >
        <div style="float: left; margin-top: 14px; margin-left: 20px">
          <label>核心企业</label>
        </div>
        <el-button
          icon="el-icon-download"
          size="small"
          @click="exportExcel"
          style="position: relative; left: 80%; top: 10px"
          >导出Excel</el-button
        >
      </div>
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        border
        element-loading-text="拼命加载中"
        style="width: 100%"
      >
        <el-table-column align="center" type="selection" width="60">
        </el-table-column>
        <el-table-column prop="eid" label="客户编号" width="160">
        </el-table-column>
        <el-table-column prop="ename" label="客户名称" width="160">
        </el-table-column>
        <el-table-column sortable prop="username" label="管理员" width="100">
        </el-table-column>
        <el-table-column
          sortable
          prop="phonenum"
          label="管理员手机"
          width="160"
        >
        </el-table-column>
        <el-table-column sortable prop="tier" label="供应链层级" width="160">
        </el-table-column>
        <el-table-column sortable prop="num" label="下级客户数量" width="160">
        </el-table-column>
        <el-table-column sortable prop="estatus" label="客户状态" width="160">
        </el-table-column>
        <el-table-column align="center" label="操作" min-width="300">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="show(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog title="供应链查看" :visible.sync="editFormVisible">
      <el-form :model="editForm" label-position="left" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称">
              <el-input
                v-model="editForm.ename"
                :disabled="true"
                style="width: 220px"
              ></el-input> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="企业地址">
              <el-input
                v-model="editForm.address"
                :disabled="true"
                style="width: 220px"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="管理员">
              <el-input
                v-model="editForm.username"
                :disabled="true"
                style="width: 220px"
              ></el-input> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="管理员手机">
              <el-input
                v-model="editForm.phonenum"
                :disabled="true"
                style="width: 220px"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>

        <el-row>
          <el-form-item label="供应链企业">
            <el-tree
              :data="supplyList"
              default-expand-all
              node-key="eid"
              :props="defaultProps"
              ref="tree"
              @check-change="getCheckedKeys2"
              :default-checked-keys="editForm.eids"
            >
            </el-tree>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editFormVisible = false"
          >返回</el-button
        >
      </div>
    </el-dialog>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
  </div>
</template>

<script>
import switchOne from '../../components/switchOne.vue'
import { deptList, deptSave, deptDelete } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      editFormVisible: false,
      defaultProps: {
        children: 'enterprises',
        label: 'ename'
      },
      supplyList: [],
      bankOption: [],
      createNetworkDialog: false,
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        eid: "",
        ename: "",
        username: "",
        address: "",
        phonenum: "",
        enterprises: [],

      },
      formInline: {
        currentPage: 1,
        pageSize: 10,
        ename: "",
        phonenum: ""
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination,
    switchOne
  },

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    //将当前页数据导出为Excel
    exportExcel() {
      var form = document.createElement("form");
      form.style.display = "none";
      form.action = '/api/supply/exportExcel';
      form.method = "post";
      document.body.appendChild(form);
      var input = document.createElement("input");
      input.type = "hidden";
      input.name = "json";
      input.value = window.JSON.stringify(this.formInline);
      form.appendChild(input);
      form.submit();
      form.remove();
    },

    show(row) {
      console.log(row)
      this.editFormVisible = true
      this.editForm.ename = row.ename
      this.editForm.address = row.address
      this.editForm.phonenum = row.phonenum
      this.editForm.username = row.username
      this.editForm.enterprises = row.enterprises
      this.editForm.eid = row.eid
      this.supplyList = []
      //查询核心企业对应的供应链
      this.$axios.get('/api/supply/findById/' + this.editForm.eid)
        .then(res => {
          console.log(res.data.data[0].enterprises);
          this.loading = false
          if (res.data.code == 200) {
            this.$message({
              type: 'info',
              message: res.data.message
            })
            this.supplyList = res.data.data[0].enterprises
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('供应链加载失败，请稍后再试！')
        })
    },
    getCheckedKeys2() {
      console.log(this.$refs.tree.getCheckedKeys());
      this.editForm.eids = this.$refs.tree.getCheckedKeys()
    },
    getdata() {
      this.loading = true
      //查询所有供应链
      this.$axios.post('/api/supply/all/', this.formInline)
        .then(res => {
          console.log(res);
          this.loading = false
          if (res.data.code == 200) {
            this.$message({
              type: 'info',
              message: res.data.message
            })
            this.listData = res.data.data.list
            // 分页赋值
            this.pageparm.currentPage = this.formInline.currentPage
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('供应链加载失败，请稍后再试！')
        })

    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.currentPage = parm.currentPage
      this.formInline.pageSize = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.loading = true
      this.$axios.post('/api/supply/findBy/', this.formInline)
        .then(res => {
          console.log(res);
          this.loading = false
          if (res.data.code == 200) {
            this.$message({
              type: 'info',
              message: res.data.message
            })
            this.listData = res.data.data.list
            // 分页赋值
            this.pageparm.currentPage = this.formInline.currentPage
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.data.total

          } else {
            this.$message({
              type: 'info',
              message: res.data.message
            })
          }
          this.formInline.ename = ""
          this.formInline.phonenum = ""

        })
        .catch(err => {
          this.loading = false
          this.$message.error('链单网络查询失败，请稍后再试！')
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    },
    //switch开关触发事件
    changeSwitch(row) {
      console.log(row.id)
      if (row.status == 1) {
        this.$confirm('确定要禁用吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$axios.post('/api/network/updateStatus/', row)
              .then(res => {
                if (res.data.code == 200) {
                  this.$message({
                    type: 'success',
                    message: '流转网络已禁用!'
                  })
                } else {
                  this.$message({
                    type: 'info',
                    message: res.msg
                  })
                }
              })
              .catch(err => {
                this.loading = false
                this.$message.error('流转网络禁用失败，请稍后再试！')
              })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消禁用'
            })
          })
      } else {
        this.$confirm('确定要启用吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$axios.post('/api/network/updateStatus/', row)
              .then(res => {
                if (res.data.code == 200) {
                  this.$message({
                    type: 'success',
                    message: '流转网络已启用!'
                  })
                } else {
                  this.$message({
                    type: 'info',
                    message: res.msg
                  })
                }
              })
              .catch(err => {
                this.loading = false
                this.$message.error('流转网络启用失败，请稍后再试！')
              })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消启用'
            })
          })
      }

    }
  }
}
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
  /* &:last-child {
    margin-bottom: 0;
  } */
}
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.create-course-dialog .el-dialog {
  margin-top: 40px !important;
  width: 1000px;
  height: 820px;
  position: relative;
}
.create-course-dialog .el-upload {
  width: 100px;
  position: relative;
  left: 5px;
  top: 5px;
}
.create-course-dialog img {
  width: 100%;
  height: 100%;
}
.create-course-dialog .el-dialog__title {
  font-size: 30px;
}
.create-course-dialog .el-form-item__label {
  font-size: 18px;
  width: 90px;
}
.create-course-dialog .el-form-item {
  margin-top: 10px;
}
.create-course-dialog .el-input {
  width: 250px;
}
.create-course-dialog .dialog-left {
  float: left;
  border: 1px #bababa solid;
  border-radius: 5px;
  width: 420px;
  height: 380px;
  position: relative;
}
.create-course-dialog .dialog-right {
  float: right;
  border: 1px #bababa solid;
  border-radius: 5px;
  width: 500px;
  height: 380px;
}
.create-course-dialog .dialog-footer {
  position: absolute;
  bottom: 20px;
  right: 30px;
}
.create-course-dialog .el-input-number .el-input {
  width: 100%;
}
.create-course-dialog .el-input-number {
  width: 100px;
}
.create-course-dialog .el-form-item__error {
  margin-left: 90px;
}
.el-popover {
  max-width: 860px;
  max-height: 760px;
  overflow: auto;
}
.small-img img {
  height: 100px;
}
.small-img {
  padding: 5px;
  float: left;
}
</style>


